/**
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

% additional_deprecated_opcodes = ["JNSTRICTEQUNDEFINED",
%                                 "JSTRICTEQUNDEFINED",
%                                 "JNEUNDEFINED",
%                                 "JEQUNDEFINED",
%                                 "JNSTRICTEQNULL",
%                                 "JSTRICTEQNULL",
%                                 "JNENULL",
%                                 "JEQNULL",
%                                 "JNSTRICTEQZ",
%                                 "JSTRICTEQZ",
%                                 "STTOGLOBALRECORD",
%                                 "STCONSTTOGLOBALRECORD",
%                                 "CREATEREGEXPWITHLITERAL",
%                                 "CLOSEITERATOR"]

% replaced_opcodes = ["JNSTRICTEQ",
%                    "JSTRICTEQ",
%                    "JNE",
%                    "JEQ"]

% skipped_opcodes = additional_deprecated_opcodes + replaced_opcodes

// NOLINTNEXTLINE(readability-function-size)
void libabckit::CodeGenDynamic::VisitEcma(ark::compiler::GraphVisitor *visitor, Inst *instBase)
{
    ASSERT(instBase->IsIntrinsic());
    auto inst = instBase->CastToIntrinsic();
    auto enc = static_cast<CodeGenDynamic *>(visitor);

    switch (inst->GetIntrinsicId()) {
% instructions = Panda::instructions.select{|b| b.namespace == "ecmascript"}
% if instructions.first && instructions.first.intrinsic_name
%   instructions = instructions.group_by(&:intrinsic_name)
% else
%   instructions = instructions.group_by(&:opcode)
% end
% instructions.each do |intrinsic_name, group|
%   inst = group.first
%   if !(inst.opcode.upcase.include? "DEPRECATED_") && !(skipped_opcodes.include? inst.mnemonic.upcase)
%     next if inst.properties.include?("jump")
%     opcode = inst.opcode.upcase
%     params_arr = inst.operands
%     group.each do |i|
%       intr_id = i.opcode.upcase
        case ark::compiler::RuntimeInterface::IntrinsicId::DYN_<%= intr_id %>: {
%     end
%     acc_read = inst.acc.include?("in")
%     if acc_read
            auto accSrc = inst->GetSrcReg(0);
            if (accSrc != ark::compiler::GetAccReg()) {
                DoLda(accSrc, enc->result_);
            }
%     end
%     params_str = ""
%     vreg_index = 0
%     imm_index = 0
%     id_index = 0
%     input_index = acc_read ? 1 : 0
%     params_arr.each do |param|
%       if param.reg?
            auto v<%= vreg_index %> = inst->GetSrcReg(<%= input_index %>);
%           params_str = params_str + "v#{vreg_index}, "
%         vreg_index = vreg_index + 1
%         input_index = input_index + 1
%       elsif param.id?
%         if param.method_id?
            // NOLINTNEXTLINE(readability-container-size-empty)
            ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>);
            auto irId<%= id_index %> = static_cast<uint32_t>(inst->GetImms()[<%= imm_index %>]);
            auto bcId<%= id_index %> = enc->irInterface_->GetMethodIdByOffset(irId<%= id_index %>);
%           params_str = params_str + "bcId#{id_index}, "
%         elsif param.string_id?
            // NOLINTNEXTLINE(readability-container-size-empty)
            ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>);
            auto irId<%= id_index %> = static_cast<uint32_t>(inst->GetImms()[<%= imm_index %>]);
            auto bcId<%= id_index %> = enc->irInterface_->GetStringIdByOffset(irId<%= id_index %>);
%           params_str = params_str + "bcId#{id_index}, "
%         elsif param.literalarray_id?
            // NOLINTNEXTLINE(readability-container-size-empty)
            ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>);
            auto irId<%= id_index %> = static_cast<uint32_t>(inst->GetImms()[<%= imm_index %>]);
            auto bcId<%= id_index %> = enc->irInterface_->GetLiteralArrayIdByOffset(irId<%= id_index %>);
%           params_str = params_str + "bcId#{id_index}, "
%         end
%         id_index = id_index + 1
%         imm_index = imm_index + 1
%       elsif param.imm?
            // NOLINTNEXTLINE(readability-container-size-empty)
            ASSERT(inst->HasImms() && inst->GetImms().size() > <%= imm_index %>);
%          if inst.properties.include?("jump")
%            params_str += "LabelName(inst->GetBasicBlock()->GetTrueSuccessor()->GetId()), "
%          else
            auto imm<%= imm_index %> = static_cast<uint32_t>(inst->GetImms()[<%= imm_index %>]);
%           params_str = params_str + "imm#{imm_index}, "
%           imm_index = imm_index + 1
%         end
%       end
%     end
%     if params_arr.length > 0
%       params_str = params_str.chop
%       params_str = params_str.chop
%     end
            enc->result_.emplace_back(PandasmWrapper::Create_<%= inst.asm_token %>_Wrapper(<%= params_str %>));
%     if inst.acc.include?("out")
            auto accDst = inst->GetDstReg();
            if (accDst != ark::compiler::GetAccReg()) {
                DoSta(inst->GetDstReg(), enc->result_);
            }
%     end
            break; }
%   end
% end
        default:
            enc->success_ = false;
            LOG(ERROR,COMPILER) << "Unsupported ecma opcode";
    }
}
